package com.cskaoyan.connectionpool.opensource;

import com.mchange.v2.c3p0.ComboPooledDataSource;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.SQLException;

/**
 * 创建日期: 2022/08/27 10:56
 *
 * @author ciggar
 */
public class C3p0Utils2 {

    // 声明一个数据库连接池
    static DataSource dataSource;

    static {

        try {
            dataSource = new ComboPooledDataSource("cskaoyan");

        }catch (Exception ex) {
            ex.printStackTrace();
        }


    }

    // 获取连接的方法
    public static Connection getConnection(){

        Connection connection = null;
        try {
            connection = dataSource.getConnection();
        } catch (SQLException e) {
            e.printStackTrace();
        }

        return connection;
    }
}
